#ifndef STRING_C__
#define STRING_C__

#include <stdlib.h>

#if 0
import std.lib;
#endif

struct StringList { char* head; struct StringList* tail; };

struct StringList* allocateStringList(char* head, struct StringList* tail)
{
	struct StringList* r = malloc(sizeof(struct StringList));
	r->head = head;
	r->tail = tail;
	return r;
}

struct StringList* stringListAppend(struct StringList* list, char* s)
{
	if(list == NULL)
		return allocateStringList(s,NULL);

	list->tail = stringListAppend(list->tail,s);
	return list;
}

char* stringIndent(char* string)
{
	char* p = string;
	int lines = 1;
	while(*p != '\0')
	{
		if(*p == '\n')
			lines++;

		p++;
	}

	char* r = malloc(p - string + lines + 1);
	p = r;
	*p = '\t';
	p++;

	while(*string != '\0')
	{
		*p = *string;
		if(*string == '\n')
		{
			p++;
			*p = '\t';
		}

		p++;
		string++;
	}

	return r;
}

int stringStartsWith(char* left, char* right)
{
	if(left == right)
		return 1;

	if(left == NULL || right == NULL)
		return 0;

	while(*left == *right)
	{
		if(*left == '\0')
			return 1;

		left++;
		right++;
	}

	if(*right == '\0')
		return 1;

	return 0;
}

#endif
